import { getIndexInfo, indexGroup, getLabelInfo, labelGroup } from '@/api/labelmanagement.js'
const labelManagement = {
  state: {
    indexData: [],
    indexGroupData: [],
    labelData: [],
    labelGroupData: []
  },
  mutations: {
    SET_INDEXDATA: (state, indexData) => {
      state.indexData = indexData
    },
    SET_INDEXGROUPDATA: (state, indexGroupData) => {
      state.indexGroupData = indexGroupData
    },
    SET_LABELDATA: (state, labelData) => {
      state.labelData = labelData
    },
    SET_LABELGROUPDATA: (state, labelGroupData) => {
      state.labelGroupData = labelGroupData
    }
  },
  actions: {

    // 获取指标信息
    IndexGetInfo({ commit }) {
      return new Promise((resolve, reject) => {
        console.log('IndexGetInfo')
        getIndexInfo().then(response => {
          console.log('getInfo')
          const data = response.data
          commit('SET_INDEXDATA', data)
          console.log(data)
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 指标组合
    IndexGroup({ commit }) {
      return new Promise((resolve, reject) => {
        console.log('IndexGroup')
        indexGroup().then(response => {
          console.log('getInfo')
          const data = response.data
          commit('SET_INDEXGROUPDATA', data)
          console.log(data)
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 获取标签信息
    LabelGetInfo({ commit }) {
      return new Promise((resolve, reject) => {
        console.log('LabelGetInfo')
        getLabelInfo().then(response => {
          console.log('getInfo')
          const data = response.data
          commit('SET_LABELDATA', data)
          console.log(data)
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 标签组合
    LabelGroup({ commit }) {
      return new Promise((resolve, reject) => {
        console.log('LabelGroup')
        labelGroup().then(response => {
          console.log('getInfo')
          const data = response.data
          commit('SET_LABELGROUPDATA', data)
          console.log(data)
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
}

export default labelManagement
